package logic

import (
	"context"
	"info-hub/pkg"
	"net/http"

	"info-hub/api/internal/svc"
	"info-hub/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UploadApiLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUploadApiLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadApiLogic {
	return &UploadApiLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UploadApiLogic) UploadApi(req *http.Request) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	file, m, err := req.FormFile("image")
	if err != nil {
		return nil, err
	}
	qny, err := pkg.Qny(file, m)
	if err != nil {
		return nil, err
	}

	return &types.Response{
		Message: "图片上传",
		Code:    200,
		Data:    qny,
	}, nil
}
